<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.3"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: VGA/DirectVGA_ElMuro/DirectVGA_ElMuro.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.3 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('_v_g_a_2_direct_v_g_a__el_muro_2_direct_v_g_a__el_muro_8ino-example.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">VGA/DirectVGA_ElMuro/DirectVGA_ElMuro.ino</div></div>
</div><!--header-->
<div class="contents">
<p >Sample breakout-style game using VGADirectController base class, from Carles Oriol</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - www.fabgl.com</span></div>
<div class="line"><span class="comment">  Copyright (c) 2019-2020 Fabrizio Di Vittorio.</span></div>
<div class="line"><span class="comment">  All rights reserved.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  This file is part of FabGL Library.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div>
<div class="line"><span class="comment">  (at your option) any later version.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div>
<div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><span class="comment">  GNU General Public License for more details.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><a id="_a0" name="_a0"></a><a class="code hl_class" href="classfabgl_1_1_v_g_a_direct_controller.html">fabgl::VGADirectController</a> DisplayController;</div>
<div class="line"><a id="_a1" name="_a1"></a><a class="code hl_class" href="classfabgl_1_1_p_s2_controller.html">fabgl::PS2Controller</a>       PS2Controller;</div>
<div class="line">SoundGenerator             soundGenerator;</div>
<div class="line">SquareWaveformGenerator    swg;</div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;controllers.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;soundchip.h&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define TOPMARGIN 6</span></div>
<div class="line"><span class="preprocessor">#define SIDEMARGIN 14</span></div>
<div class="line"><span class="preprocessor">#define INITIALDIR (-PI/2+.5)</span></div>
<div class="line"><span class="preprocessor">#define INITIALY 180</span></div>
<div class="line"><span class="preprocessor">#define INITIALX 150</span></div>
<div class="line"><span class="preprocessor">#define PADDLES 3</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">volatile</span> <span class="keywordtype">double</span>      objX    = INITIALX;</div>
<div class="line"><span class="keyword">volatile</span> <span class="keywordtype">double</span>      objY    = INITIALY;</div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">double</span>        objDir  = INITIALDIR;</div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">double</span>        objVel  =  4;</div>
<div class="line"><span class="keyword">static</span> <span class="keyword">constexpr</span> <span class="keywordtype">int</span> objSize =  8;</div>
<div class="line"><span class="keyword">static</span> TaskHandle_t  mainTaskHandle;</div>
<div class="line"><span class="keyword">static</span> uint32_t      bgParkMillerState = 1;</div>
<div class="line"><span class="keywordtype">long</span> offGame = 0;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// just to avoid floating point calculations inside MyDirectDrawVGAController::drawScanline()</span></div>
<div class="line"><span class="keyword">volatile</span> <span class="keywordtype">int</span> objIntX;</div>
<div class="line"><span class="keyword">volatile</span> <span class="keywordtype">int</span> objIntY;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> nBricks = 0;</div>
<div class="line"><span class="keywordtype">bool</span> brickMap[8][12];</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> paddlePos = 320/2;</div>
<div class="line"><span class="keywordtype">int</span> nPaddles = PADDLES;</div>
<div class="line"> </div>
<div class="line">GameControllerMouse      cMouse;</div>
<div class="line">GameControllerKeys       cKeysArrows;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keyword">inline</span> <span class="keywordtype">int</span> fastRandom()</div>
<div class="line">{</div>
<div class="line">  bgParkMillerState = (uint64_t)bgParkMillerState * 48271 % 0x7fffffff;</div>
<div class="line">  <span class="keywordflow">return</span> bgParkMillerState % 4;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> IRAM_ATTR drawScanline(<span class="keywordtype">void</span> * arg, uint8_t * dest, <span class="keywordtype">int</span> scanLine)</div>
<div class="line">{</div>
<div class="line">  <span class="keyword">auto</span> fgcolor = DisplayController.createRawPixel(RGB222(3, 3, 3));   </div>
<div class="line">  <span class="keyword">auto</span> white = DisplayController.createRawPixel(RGB222(3, 3, 3));   </div>
<div class="line">  <span class="keyword">auto</span> black = DisplayController.createRawPixel(RGB222(0, 0, 0));   </div>
<div class="line">  <span class="keyword">auto</span> bgcolor = DisplayController.createRawPixel(RGB222(0, 0, 0)); </div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span>( scanLine &gt;= 32 )</div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">if</span>(scanLine &lt; 32+16)</div>
<div class="line">    {</div>
<div class="line">      bgcolor = DisplayController.createRawPixel(RGB222(1, 0, 0));</div>
<div class="line">      fgcolor = DisplayController.createRawPixel(RGB222(3, 0, 0));</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(scanLine &lt; 32+16+16)</div>
<div class="line">    {</div>
<div class="line">      bgcolor = DisplayController.createRawPixel(RGB222(1, 0, 1));</div>
<div class="line">      fgcolor = DisplayController.createRawPixel(RGB222(3, 0, 3));</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(scanLine &lt; 32+16+16+16)</div>
<div class="line">    {</div>
<div class="line">      bgcolor = DisplayController.createRawPixel(RGB222(0, 1, 0));     </div>
<div class="line">      fgcolor = DisplayController.createRawPixel(RGB222(0, 3, 0));     </div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(scanLine &lt; 32+16+16+16+16)</div>
<div class="line">    {</div>
<div class="line">      bgcolor = DisplayController.createRawPixel(RGB222(1, 1, 0));    </div>
<div class="line">      fgcolor = DisplayController.createRawPixel(RGB222(3, 3, 0));     </div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keyword">auto</span> <a id="a2" name="a2"></a><a class="code hl_variable" href="displaycontroller_8h_a2474a5474cbff19523a51eb1de01cda4.html#a2474a5474cbff19523a51eb1de01cda4">width</a> = DisplayController.<a id="a3" name="a3"></a><a class="code hl_function" href="classfabgl_1_1_base_display_controller_a749df909b39fd096bf6e2813f2f5324c.html#a749df909b39fd096bf6e2813f2f5324c">getScreenWidth</a>();</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// fill line with background color</span></div>
<div class="line">  <span class="keywordflow">if</span>( scanLine &lt; TOPMARGIN)</div>
<div class="line">    memset(dest+8, fgcolor, <a class="code hl_variable" href="displaycontroller_8h_a2474a5474cbff19523a51eb1de01cda4.html#a2474a5474cbff19523a51eb1de01cda4">width</a>-16);</div>
<div class="line">  <span class="keywordflow">else</span></div>
<div class="line">  {</div>
<div class="line">    memset(dest, black, 16);</div>
<div class="line">    memset(dest+319-15, black, 16);</div>
<div class="line">    memset(dest+16, bgcolor, <a class="code hl_variable" href="displaycontroller_8h_a2474a5474cbff19523a51eb1de01cda4.html#a2474a5474cbff19523a51eb1de01cda4">width</a>-32);</div>
<div class="line">    <span class="keywordflow">for</span>( <span class="keywordtype">int</span> ncompta = 8; ncompta &lt; SIDEMARGIN; ncompta++)</div>
<div class="line">    {</div>
<div class="line">      VGA_PIXELINROW(dest, ncompta) = white;</div>
<div class="line">      VGA_PIXELINROW(dest, 319-ncompta) = white;    </div>
<div class="line">    }</div>
<div class="line">  }  </div>
<div class="line"> </div>
<div class="line">  <span class="comment">// fill object with foreground color</span></div>
<div class="line">  <span class="keywordflow">if</span> (scanLine &gt;= objIntY - objSize / 2 &amp;&amp; scanLine &lt;= objIntY + objSize / 2) </div>
<div class="line">  {    </div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> col = objIntX - objSize / 2; col &lt; objIntX + objSize / 2; ++col)</div>
<div class="line">        VGA_PIXELINROW(dest, col) = fgcolor;          </div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span> (scanLine &gt;= 184 &amp;&amp; scanLine &lt; 192 ) </div>
<div class="line">  {    </div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> col = paddlePos - 16 ; col &lt; paddlePos + 16; ++col) </div>
<div class="line">        VGA_PIXELINROW(dest, col) = white;         </div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// drawBricks </span></div>
<div class="line">  <span class="keywordflow">if</span>( scanLine &gt;= 32 &amp;&amp; scanLine &lt; (32+16+16+16+16) &amp;&amp; scanLine % 8 != 0)</div>
<div class="line">  <span class="keywordflow">for</span>( <span class="keywordtype">int</span> x = 0; x &lt; 12*3*8; x++)</div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">if</span>( x%24 != 0 &amp;&amp; x%24 != 23 &amp;&amp; brickMap[(scanLine-32)/8][x/24])</div>
<div class="line">      VGA_PIXELINROW(dest, x+16) = fgcolor;</div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span>( scanLine &gt;= 10 &amp;&amp; scanLine &lt;= 13 )</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p = 0; p &lt; nPaddles; p++)</div>
<div class="line">      <span class="keywordflow">for</span>( <span class="keywordtype">int</span> x = 0; x &lt; 10; x++)</div>
<div class="line">        VGA_PIXELINROW(dest, 300 - x - p*14) = white;</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span> (scanLine == DisplayController.<a id="a4" name="a4"></a><a class="code hl_function" href="classfabgl_1_1_base_display_controller_a0872427e4a351bb3590e8d00096e9cba.html#a0872427e4a351bb3590e8d00096e9cba">getScreenHeight</a>() - 1) {</div>
<div class="line">    <span class="comment">// signal end of screen</span></div>
<div class="line">    vTaskNotifyGiveFromISR(mainTaskHandle, NULL);</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> resetGame()</div>
<div class="line">{</div>
<div class="line">  memset( brickMap, <span class="keyword">true</span>, <span class="keyword">sizeof</span>(brickMap));</div>
<div class="line">  nBricks = 12*8;</div>
<div class="line">  objIntX = objX = INITIALX;</div>
<div class="line">  objIntY = objY    = INITIALY;</div>
<div class="line">  objDir  = INITIALDIR;</div>
<div class="line">  offGame = millis();</div>
<div class="line">  nPaddles = PADDLES;</div>
<div class="line"> </div>
<div class="line">  playSoundReset();</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> setup()</div>
<div class="line">{</div>
<div class="line">  Serial.begin(115200); delay(500); Serial.write(<span class="stringliteral">&quot;\n\n\n&quot;</span>); <span class="comment">// DEBUG ONLY</span></div>
<div class="line"> </div>
<div class="line">  PS2Controller.<a id="a5" name="a5"></a><a class="code hl_function" href="classfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09.html#ab8520612804a921ad834b41214a99c09">begin</a>(PS2Preset::KeyboardPort0_MousePort1, KbdMode::GenerateVirtualKeys);</div>
<div class="line">  cMouse = GameControllerMouse (0);</div>
<div class="line">  cKeysArrows = GameControllerKeys (1, <a id="a6" name="a6"></a><a class="code hl_enumvalue" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a5e6713ca12a9359631fa25166a14db51">fabgl::VK_UP</a>, <a id="a7" name="a7"></a><a class="code hl_enumvalue" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a839718d2d233e445b65286817a0a0f2d">fabgl::VK_DOWN</a>, <a id="a8" name="a8"></a><a class="code hl_enumvalue" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02ad1093d0c4350abe99ccd39bd6717020d">fabgl::VK_LEFT</a>, <a id="a9" name="a9"></a><a class="code hl_enumvalue" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02aea80fc6815468c273ef3674aa7eae7f1">fabgl::VK_RIGHT</a>, <a id="a10" name="a10"></a><a class="code hl_enumvalue" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02af9ef1e33ad1f245c806a26885014009d">fabgl::VK_RSHIFT</a>, <a id="a11" name="a11"></a><a class="code hl_enumvalue" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a292abb1d79755a30f0316d7b13478f98">fabgl::VK_ESCAPE</a>);</div>
<div class="line"> </div>
<div class="line">  mainTaskHandle = xTaskGetCurrentTaskHandle();</div>
<div class="line"> </div>
<div class="line">  DisplayController.begin();</div>
<div class="line">  DisplayController.<a id="a12" name="a12"></a><a class="code hl_function" href="classfabgl_1_1_v_g_a_direct_controller_a18497a8f427eca28ee4bc4fed3a76508.html#a18497a8f427eca28ee4bc4fed3a76508">setDrawScanlineCallback</a>(drawScanline);</div>
<div class="line">  DisplayController.<a id="a13" name="a13"></a>setResolution(<a id="a14" name="a14"></a><a class="code hl_define" href="fabglconf_8h_a053cde6629b66d4ba3e31e92af8861bb.html#a053cde6629b66d4ba3e31e92af8861bb">VGA_320x200_75Hz</a>);</div>
<div class="line">  soundGenerator.setVolume(127);</div>
<div class="line">  soundGenerator.play(<span class="keyword">true</span>);</div>
<div class="line">  soundGenerator.attach( &amp;swg);</div>
<div class="line"> </div>
<div class="line">  resetGame();</div>
<div class="line">  delay(3000);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> loop()</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">if</span>( millis() - offGame &gt; 4000)</div>
<div class="line">    offGame = <span class="keyword">false</span>;</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// check brick collision</span></div>
<div class="line">  <span class="keyword">static</span> <span class="keywordtype">int</span> oldbricky = -1;</div>
<div class="line">  <span class="keywordtype">int</span> brickx = (objIntX-16)/24;</div>
<div class="line">  <span class="keywordtype">int</span> bricky = (objIntY-32)/8;</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>( bricky &gt;= 0 &amp;&amp; bricky &lt;8 &amp;&amp; brickx &lt; 12 &amp;&amp; brickMap[bricky][brickx] )</div>
<div class="line">  {</div>
<div class="line">      brickMap[bricky][brickx] = <span class="keyword">false</span>;</div>
<div class="line">      nBricks--;      </div>
<div class="line">      objDir = (( bricky != oldbricky ) ? 2 : 1) * PI - objDir;    </div>
<div class="line">      playSoundPic();     </div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span>( nBricks == 0) resetGame();</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// test collision with borders and bounce changing direction</span></div>
<div class="line">  <span class="keywordflow">if</span> (objX &lt; objSize / 2 +SIDEMARGIN|| objX &gt; DisplayController.<a class="code hl_function" href="classfabgl_1_1_base_display_controller_a749df909b39fd096bf6e2813f2f5324c.html#a749df909b39fd096bf6e2813f2f5324c">getScreenWidth</a>() - objSize / 2-SIDEMARGIN)</div>
<div class="line">  {</div>
<div class="line">    objDir = PI - objDir;</div>
<div class="line">    playSoundPong();</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (objY &lt; objSize / 2 +TOPMARGIN ) </div>
<div class="line">  {</div>
<div class="line">    objDir = 2 * PI - objDir;    </div>
<div class="line">    playSoundPong();</div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line">  <span class="keywordtype">double</span> sdir = sin(objDir);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// check paddle collision  </span></div>
<div class="line">  <span class="keywordflow">if</span> ( !offGame &amp;&amp; objX &gt; paddlePos -(16+objSize/2) &amp;&amp; objX &lt; paddlePos +(16+objSize/2) &amp;&amp; objY &gt; 184-objSize/2 &amp;&amp; objY&lt; 192 &amp;&amp; sdir &gt;= 0)</div>
<div class="line">  {    </div>
<div class="line">    objDir = 2 * PI - objDir;      </div>
<div class="line">    objDir += (objX - ((double)paddlePos))*((PI/2.0)/32.0);</div>
<div class="line">    playSoundTuc();</div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span>( !offGame )</div>
<div class="line">  {</div>
<div class="line">    sdir = sin(objDir);</div>
<div class="line">    <span class="comment">// calculate new coordinates  </span></div>
<div class="line">    objX += objVel * cos(objDir);</div>
<div class="line">    objY += objVel * sdir;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">else</span></div>
<div class="line">    objX = paddlePos +8;</div>
<div class="line">    </div>
<div class="line">  <span class="keywordflow">if</span>(objY &lt; 7) objY = 8;</div>
<div class="line">  <span class="keywordflow">if</span>( objX &lt; 16  ) objX =  16 ;</div>
<div class="line">  <span class="keywordflow">if</span>( objX &gt; 319-16 ) objX = 319-16;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Ball lost</span></div>
<div class="line">  <span class="keywordflow">if</span>(objY &gt; 200) </div>
<div class="line">  {</div>
<div class="line">    playSoundOut();</div>
<div class="line">    offGame = millis();</div>
<div class="line">    nPaddles--;</div>
<div class="line">    <span class="keywordflow">if</span>( nPaddles == -1)</div>
<div class="line">      resetGame();</div>
<div class="line">    <span class="keywordflow">else</span></div>
<div class="line">    {</div>
<div class="line">      objY = INITIALY;</div>
<div class="line">      objDir  = INITIALDIR;      </div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// convert object coordinate to integer</span></div>
<div class="line">  objIntX = objX;</div>
<div class="line">  objIntY = objY;</div>
<div class="line"> </div>
<div class="line">  oldbricky = bricky;</div>
<div class="line"> </div>
<div class="line">  cMouse.update();</div>
<div class="line">  paddlePos += cMouse.getDX();</div>
<div class="line">  <span class="keywordflow">if</span>( cKeysArrows.isLeft() ) paddlePos -= 8;</div>
<div class="line">  <span class="keywordflow">if</span>( cKeysArrows.isRight() ) paddlePos += 8;</div>
<div class="line">  <span class="keywordflow">if</span>( cMouse.isButtonA() || cKeysArrows.isButtonA() )</div>
<div class="line">    offGame = <span class="keyword">false</span>;</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>( paddlePos &lt; 32) paddlePos = 32; </div>
<div class="line">  <span class="keywordflow">if</span>( paddlePos &gt; 319-32) paddlePos = 319-32; </div>
<div class="line"> </div>
<div class="line">  <span class="comment">// wait for vertical sync</span></div>
<div class="line">  ulTaskNotifyTake(pdTRUE, portMAX_DELAY);</div>
<div class="line">}</div>
<div class="ttc" id="aclassfabgl_1_1_base_display_controller_a0872427e4a351bb3590e8d00096e9cba_html_a0872427e4a351bb3590e8d00096e9cba"><div class="ttname"><a href="classfabgl_1_1_base_display_controller_a0872427e4a351bb3590e8d00096e9cba.html#a0872427e4a351bb3590e8d00096e9cba">fabgl::BaseDisplayController::getScreenHeight</a></div><div class="ttdeci">int getScreenHeight()</div><div class="ttdoc">Determines the screen height in pixels.</div><div class="ttdef"><b>Definition:</b> <a href="displaycontroller_8h_source.html#l00696">displaycontroller.h:696</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_base_display_controller_a749df909b39fd096bf6e2813f2f5324c_html_a749df909b39fd096bf6e2813f2f5324c"><div class="ttname"><a href="classfabgl_1_1_base_display_controller_a749df909b39fd096bf6e2813f2f5324c.html#a749df909b39fd096bf6e2813f2f5324c">fabgl::BaseDisplayController::getScreenWidth</a></div><div class="ttdeci">int getScreenWidth()</div><div class="ttdoc">Determines the screen width in pixels.</div><div class="ttdef"><b>Definition:</b> <a href="displaycontroller_8h_source.html#l00689">displaycontroller.h:689</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09_html_ab8520612804a921ad834b41214a99c09"><div class="ttname"><a href="classfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09.html#ab8520612804a921ad834b41214a99c09">fabgl::PS2Controller::begin</a></div><div class="ttdeci">static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)</div><div class="ttdoc">Initializes PS2 device controller.</div><div class="ttdef"><b>Definition:</b> <a href="ps2controller_8cpp_source.html#l01115">ps2controller.cpp:1115</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_p_s2_controller_html"><div class="ttname"><a href="classfabgl_1_1_p_s2_controller.html">fabgl::PS2Controller</a></div><div class="ttdoc">The PS2 device controller class.</div><div class="ttdef"><b>Definition:</b> <a href="ps2controller_8h_source.html#l00082">ps2controller.h:82</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_v_g_a_direct_controller_a18497a8f427eca28ee4bc4fed3a76508_html_a18497a8f427eca28ee4bc4fed3a76508"><div class="ttname"><a href="classfabgl_1_1_v_g_a_direct_controller_a18497a8f427eca28ee4bc4fed3a76508.html#a18497a8f427eca28ee4bc4fed3a76508">fabgl::VGADirectController::setDrawScanlineCallback</a></div><div class="ttdeci">void setDrawScanlineCallback(DrawScanlineCallback drawScanlineCallback, void *arg=nullptr)</div><div class="ttdoc">Sets the callback used when VGADirectController needs to prepare a new scanline to be sent to the VGA...</div><div class="ttdef"><b>Definition:</b> <a href="vgadirectcontroller_8h_source.html#l00116">vgadirectcontroller.h:116</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_v_g_a_direct_controller_html"><div class="ttname"><a href="classfabgl_1_1_v_g_a_direct_controller.html">fabgl::VGADirectController</a></div><div class="ttdoc">Represents a base abstract class for direct draw VGA controller.</div><div class="ttdef"><b>Definition:</b> <a href="vgadirectcontroller_8h_source.html#l00077">vgadirectcontroller.h:77</a></div></div>
<div class="ttc" id="adisplaycontroller_8h_a2474a5474cbff19523a51eb1de01cda4_html_a2474a5474cbff19523a51eb1de01cda4"><div class="ttname"><a href="displaycontroller_8h_a2474a5474cbff19523a51eb1de01cda4.html#a2474a5474cbff19523a51eb1de01cda4">width</a></div><div class="ttdeci">uint8_t width</div><div class="ttdef"><b>Definition:</b> <a href="displaycontroller_8h_source.html#l00002">displaycontroller.h:2</a></div></div>
<div class="ttc" id="afabgl_8h_html"><div class="ttname"><a href="fabgl_8h.html">fabgl.h</a></div><div class="ttdoc">This file is the all in one include file. Application can just include this file to use FabGL library...</div></div>
<div class="ttc" id="afabglconf_8h_a053cde6629b66d4ba3e31e92af8861bb_html_a053cde6629b66d4ba3e31e92af8861bb"><div class="ttname"><a href="fabglconf_8h_a053cde6629b66d4ba3e31e92af8861bb.html#a053cde6629b66d4ba3e31e92af8861bb">VGA_320x200_75Hz</a></div><div class="ttdeci">#define VGA_320x200_75Hz</div><div class="ttdef"><b>Definition:</b> <a href="fabglconf_8h_source.html#l00183">fabglconf.h:183</a></div></div>
<div class="ttc" id="agroup___enumerations_gad0e6e31d5953384be4ea987eb3923e02_html_ggad0e6e31d5953384be4ea987eb3923e02a292abb1d79755a30f0316d7b13478f98"><div class="ttname"><a href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a292abb1d79755a30f0316d7b13478f98">fabgl::VK_ESCAPE</a></div><div class="ttdeci">@ VK_ESCAPE</div><div class="ttdef"><b>Definition:</b> <a href="fabutils_8h_source.html#l01349">fabutils.h:1349</a></div></div>
<div class="ttc" id="agroup___enumerations_gad0e6e31d5953384be4ea987eb3923e02_html_ggad0e6e31d5953384be4ea987eb3923e02a5e6713ca12a9359631fa25166a14db51"><div class="ttname"><a href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a5e6713ca12a9359631fa25166a14db51">fabgl::VK_UP</a></div><div class="ttdeci">@ VK_UP</div><div class="ttdef"><b>Definition:</b> <a href="fabutils_8h_source.html#l01376">fabutils.h:1376</a></div></div>
<div class="ttc" id="agroup___enumerations_gad0e6e31d5953384be4ea987eb3923e02_html_ggad0e6e31d5953384be4ea987eb3923e02a839718d2d233e445b65286817a0a0f2d"><div class="ttname"><a href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a839718d2d233e445b65286817a0a0f2d">fabgl::VK_DOWN</a></div><div class="ttdeci">@ VK_DOWN</div><div class="ttdef"><b>Definition:</b> <a href="fabutils_8h_source.html#l01378">fabutils.h:1378</a></div></div>
<div class="ttc" id="agroup___enumerations_gad0e6e31d5953384be4ea987eb3923e02_html_ggad0e6e31d5953384be4ea987eb3923e02ad1093d0c4350abe99ccd39bd6717020d"><div class="ttname"><a href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02ad1093d0c4350abe99ccd39bd6717020d">fabgl::VK_LEFT</a></div><div class="ttdeci">@ VK_LEFT</div><div class="ttdef"><b>Definition:</b> <a href="fabutils_8h_source.html#l01380">fabutils.h:1380</a></div></div>
<div class="ttc" id="agroup___enumerations_gad0e6e31d5953384be4ea987eb3923e02_html_ggad0e6e31d5953384be4ea987eb3923e02aea80fc6815468c273ef3674aa7eae7f1"><div class="ttname"><a href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02aea80fc6815468c273ef3674aa7eae7f1">fabgl::VK_RIGHT</a></div><div class="ttdeci">@ VK_RIGHT</div><div class="ttdef"><b>Definition:</b> <a href="fabutils_8h_source.html#l01382">fabutils.h:1382</a></div></div>
<div class="ttc" id="agroup___enumerations_gad0e6e31d5953384be4ea987eb3923e02_html_ggad0e6e31d5953384be4ea987eb3923e02af9ef1e33ad1f245c806a26885014009d"><div class="ttname"><a href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02af9ef1e33ad1f245c806a26885014009d">fabgl::VK_RSHIFT</a></div><div class="ttdeci">@ VK_RSHIFT</div><div class="ttdef"><b>Definition:</b> <a href="fabutils_8h_source.html#l01341">fabutils.h:1341</a></div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 29 2022 13:52:04 for FabGL by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3 </li>
  </ul>
</div>
</body>
</html>
